# import xlwings as xw

# wb = xw.Book('工程量模板2022.xlsx')
# sht = wb.sheets['箱体线路明细']
# print('a',sht.range("C2:C9").value)
from asyncio.windows_events import NULL
import openpyxl
from openpyxl import Workbook
name = input("请输入要读取的excel名,包括后缀!!!:")
# read_only = True
excel = openpyxl.load_workbook(name,data_only=True)
name2 = input("请输入要读取的表单名:")
# 箱体线路明细
sheet = excel[name2]
rows = sheet.max_row
columns = sheet.max_column
print("行列",rows,columns)

newSheet = []
for i in range(1,rows+1):
        item = sheet.cell(i,2).value
        print(item,end="")
        if(item == "合计"):
            for j in range(2,columns+1):
                now0 = sheet.cell(2,j).value
                now = sheet.cell(i,j).value
                if(now != None and now != 0):
                    temp =[]
                    temp.append(now0)
                    temp.append(now)
                    print("\n",now0,now)
                    newSheet.append(temp)
                    temp=[]

print("\n","结束",newSheet)
newCxy = newSheet    
# 删除默认创建的一个sheet页
# ws = wb['Sheet']
# wb.remove(ws)
# 给sheet页命名
sheetName = "工作表1"
# 1.创建sheet页
ws = excel.create_sheet(sheetName)
# 构造 测试数据
row = newCxy
# 2.向工作表中 按行添加数据
ws.append(["名称","工程量"])
for i in row:
    ws.append(i)
# filePath 是指保存的 excel 文件路径
filePath = "新工作簿.xlsx"
# 3.保存xlsx
excel.save(filePath)